package owg.util;

public abstract class EntityBase
{
    private static long ID_COUNTER = 0;

    public final long id;

    private int depth;
    private boolean isDestroyed;

    private boolean visible;

    private InstanceList list;

    public EntityBase(InstanceList list){
	this(list, 0);
    }

    public EntityBase(InstanceList list, int startDepth){
	id = ID_COUNTER++;
	this.list = list;
	this.depth = startDepth;
	this.visible = true;
	list.add(this);
    }

    public long getID() {
	return id;
    }

    public void setDepth(int newDepth) {
	list.remove(this);
	this.depth = newDepth;
	list.add(this);
    }

    public int getDepth() {
	return depth;
    }
    public void destroy() {
	if(isDestroyed) {
	    System.err.println("Warning: "+this+" is already destroyed");
	    new Throwable().printStackTrace();
	    return;
	}
	list.remove(this);
	isDestroyed = true;
    }
    

    public void revive() {
	if(!isDestroyed) {
	    System.err.println("Warning: "+this+" is not yet destroyed");
	    new Throwable().printStackTrace();
	    return;
	}
	isDestroyed = false;
	list.add(this);
    }

    public boolean isDestroyed() {
	return isDestroyed;
    }

    public boolean isVisible() {
	return visible;
    }
    public void setVisible(boolean b){
	visible = b;
    }

    public abstract void beginStep();
    public abstract void step();
    public abstract void endStep();
    public abstract void render();
}
